#include <iostream>
#include <cstring>
using namespace std;

int a[5];

int main()
{
	int t; cin >> t;
	while(t--)
	{
		memset(a, 0, sizeof a);
		int n; cin >> n;
		for(int i = 1; i <= n * 4; i++)
		{
			char ch; cin >> ch;
			if(ch != '?') a[ch - 'A']++;
		}
		int ans = 0;
		for(int i = 0; i < 4; i++) ans += min(n, a[i]);
		cout << ans << endl;
	}
	return 0;
 } 
